package com.www.applyword.ui.my;

import android.content.Intent;
import android.view.View;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.classic.adapter.CommonRecyclerAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.www.applyword.Constants.Constants;
import com.www.applyword.R;
import com.www.applyword.adapter.HomeJobAdapter;
import com.www.applyword.adapter.HotJobAdapter;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.bean.JobListBean;
import com.www.applyword.bean.OrderBean;
import com.www.applyword.http.CallBack;
import com.www.applyword.http.HttpClient;
import com.www.applyword.ui.home.HomeJobActivity;
import com.www.applyword.ui.home.HotJobDetailsActivity;
import com.www.applyword.utils.ListDataSave2;
import com.www.applyword.utils.SPUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * author : huang
 * date   : 2019/10/22 0022 15:40
 * version: 1.0
 * @author Administrator
 */
public class MyEnshrineActivity extends BaseActivity {
    @BindView(R.id.rl)
    RecyclerView rlJob;

    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refresh;

    private HotJobAdapter mHotJobAdapter;
    private List<OrderBean> hotJobBeans = new ArrayList<>();

    private int page = 1;
    private int Rows = 10;

    private HomeJobAdapter homeJobAdapter;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.my_enshrine_activity);
        setTitle("我的收藏");
        initDate();
    }

    private void initDate() {
        rlJob.setLayoutManager(new LinearLayoutManager(this));
        rlJob.setItemAnimator(new DefaultItemAnimator());
        homeJobAdapter = new HomeJobAdapter(this);
        rlJob.setAdapter(homeJobAdapter);
        List<JobListBean> jobListBeans = ListDataSave2.getInstence(this).getDataList2();

            refresh.finishRefresh(true);
            if (jobListBeans.size() > 0){
                homeJobAdapter.replaceAll(jobListBeans, true);
            }else {
                showEmpty(true,vsEmpty,1);
            }

        homeJobAdapter.setOnItemClickListener(new CommonRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(RecyclerView.ViewHolder viewHolder, View view, int i) {
                startActivity(new Intent(MyEnshrineActivity.this, HomeJobActivity.class).putExtra("id",homeJobAdapter.getItem(i).getPartJobId())
                        .putExtra("jobListBeans",homeJobAdapter.getItem(i)));
            }
        });
    }

    private void getOrderList(boolean isRefresh) {
        if (isRefresh) page = 1;
        Map<String, Object> params = new HashMap<>();
        params.put("UserID", SPUtil.getString(Constants.USERID));
        params.put("Page", page + "");
        params.put("Rows", Rows + "");
        HttpClient.get(MyEnshrineActivity.this, Constants.GETCOLLECTIONLIST, params,new CallBack<List<OrderBean>>() {
            @Override
            public void onSuccess(List<OrderBean> orderBeans) {
                if (isRefresh){
                    refresh.finishRefresh(true);
                    if (orderBeans.size() == 0){
                        showEmpty(true,vsEmpty,1);
                    }else {
                        showEmpty(false, vsEmpty,1);
                    }
                    mHotJobAdapter.replaceAll(orderBeans, true);
                }else {
                    if (orderBeans.size() > 0) {
                        refresh.finishLoadMore(true);
                        mHotJobAdapter.replaceAll(orderBeans, true);
                    }else {
                        refresh.finishLoadMoreWithNoMoreData();
                    }
                }
                page++;
            }
        });
    }

    @Override
    protected void loadData() {

    }
}
